package com.material.web.controller.factory;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.material.common.utils.SecurityUtils;
import com.material.factory.vo.FactoryFuelRuleVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.material.common.annotation.Log;
import com.material.common.core.controller.BaseController;
import com.material.common.core.domain.AjaxResult;
import com.material.common.enums.BusinessType;
import com.material.factory.domain.FactoryFuelRule;
import com.material.factory.service.IFactoryFuelRuleService;
import com.material.common.utils.poi.ExcelUtil;
import com.material.common.core.page.TableDataInfo;

/**
 * 燃料检测结算奖惩规则Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/factory/rule")
public class FactoryFuelRuleController extends BaseController
{
    @Autowired
    private IFactoryFuelRuleService factoryFuelRuleService;

    /**
     * 查询燃料检测结算奖惩规则列表
     */
    @PreAuthorize("@ss.hasPermi('factory:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(FactoryFuelRule factoryFuelRule)
    {
        Long bizId = getBizId();
        boolean admin = SecurityUtils.isAdmin(getUserId());
        if(!admin){
            factoryFuelRule.setFactoryId(bizId);
        }
        startPage();
        List<FactoryFuelRuleVo> list = factoryFuelRuleService.selectFactoryFuelRulePageList(factoryFuelRule);
        return getDataTable(list);
    }

    /**
     * 导出燃料检测结算奖惩规则列表
     */
    @PreAuthorize("@ss.hasPermi('factory:rule:export')")
    @Log(title = "燃料检测结算奖惩规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FactoryFuelRule factoryFuelRule)
    {
        List<FactoryFuelRule> list = factoryFuelRuleService.selectFactoryFuelRuleList(factoryFuelRule);
        ExcelUtil<FactoryFuelRule> util = new ExcelUtil<FactoryFuelRule>(FactoryFuelRule.class);
        util.exportExcel(response, list, "燃料检测结算奖惩规则数据");
    }

    /**
     * 获取燃料检测结算奖惩规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('factory:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(factoryFuelRuleService.selectFactoryFuelRuleById(id));
    }

    /**
     * 新增燃料检测结算奖惩规则
     */
    @PreAuthorize("@ss.hasPermi('factory:rule:add')")
    @Log(title = "燃料检测结算奖惩规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FactoryFuelRule factoryFuelRule)
    {
        Long bizId = getBizId();
        boolean admin = SecurityUtils.isAdmin(getUserId());
        if(!admin){
            factoryFuelRule.setFactoryId(bizId);
        }
        return toAjax(factoryFuelRuleService.insertFactoryFuelRule(factoryFuelRule));
    }

    /**
     * 修改燃料检测结算奖惩规则
     */
    @PreAuthorize("@ss.hasPermi('factory:rule:edit')")
    @Log(title = "燃料检测结算奖惩规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FactoryFuelRule factoryFuelRule)
    {
        return toAjax(factoryFuelRuleService.updateFactoryFuelRule(factoryFuelRule));
    }

    /**
     * 删除燃料检测结算奖惩规则
     */
    @PreAuthorize("@ss.hasPermi('factory:rule:remove')")
    @Log(title = "燃料检测结算奖惩规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(factoryFuelRuleService.deleteFactoryFuelRuleByIds(ids));
    }
}
